package svc

import (
	"zerorpc/app/ogzero/rpc/demosvc/internal/config"
	"zerorpc/pkg/databases/gormx"

	_ "github.com/SpectatorNan/gorm-zero/gormc/config/mysql"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"gorm.io/gorm"
)

type ServiceContext struct {
	Config config.Config

	Data
}

type Data struct {
	TxModel gormx.TxModel
	// todo: add your data model here and delete this line
}

func NewData(db *gorm.DB, redis *redis.Redis) Data {
	return Data{
		TxModel: gormx.NewTxModel(db),
	}
}

func NewServiceContext(c config.Config) *ServiceContext {
	mysqlCli := gormx.MustNewMysql(c.Mysql)
	redisCli := redis.MustNewRedis(c.RedisConf)

	return &ServiceContext{
		Config: c,
		Data:   NewData(mysqlCli, redisCli),
	}
}
